package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizMaterial;
import com.member.shop.service.ISysBizMaterialService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【素材】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2024-05-08
 **/
@RestController
@RequestMapping("/shop/material")
public class SysBizMaterialController extends BaseController {
    @Resource
    private ISysBizMaterialService sysBizMaterialService;

    /**
     * 查询素材列表
     */
    @PreAuthorize("@ss.hasPermi('shop:material:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizMaterial sysBizMaterial) {
        startPage();
        List<SysBizMaterial> list = sysBizMaterialService.selectSysBizMaterialList(sysBizMaterial);
        return getDataTable(list);
    }

    /**
     * 导出素材列表
     */
    @PreAuthorize("@ss.hasPermi('shop:material:export')")
    @Log(title = "素材", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizMaterial sysBizMaterial) {
        LambdaQueryWrapper<SysBizMaterial> queryWrapper = new LambdaQueryWrapper<SysBizMaterial>();
        List<SysBizMaterial> list = sysBizMaterialService.selectSysBizMaterialList(queryWrapper);
        ExcelUtil<SysBizMaterial> util = new ExcelUtil<SysBizMaterial>(SysBizMaterial.class);
        util.exportExcel(response, list, "素材数据");
    }

    /**
     * 获取素材详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:material:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizMaterialService.selectSysBizMaterialById(id));
    }

    /**
     * 新增素材
     */
    @PreAuthorize("@ss.hasPermi('shop:material:add')")
    @Log(title = "素材", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizMaterial sysBizMaterial) {
        return toAjax(sysBizMaterialService.insertSysBizMaterial(sysBizMaterial));
    }

    /**
     * 修改素材
     */
    @PreAuthorize("@ss.hasPermi('shop:material:edit')")
    @Log(title = "素材", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizMaterial sysBizMaterial) {
        return toAjax(sysBizMaterialService.updateSysBizMaterial(sysBizMaterial));
    }

    /**
     * 删除素材
     */
    @PreAuthorize("@ss.hasPermi('shop:material:remove')")
    @Log(title = "素材", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizMaterialService.deleteSysBizMaterialByIds(ids));
    }
}
